package org.extremecomponents.table.view.freemarker.extend;

import org.extremecomponents.table.core.Messages;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.BuilderConstants;

//@author guanhw
public class MessageExtend {

	protected TableModel model;
	protected Messages messages;
	
	public MessageExtend(TableModel model) {
		this.model = model;
        this.messages = model.getMessages();
	}


	public String getClearText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_CLEAR_TEXT);
	}


	public String getClearTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_CLEAR_TOOLTIP);
	}


	public String getCsvText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_CSV_TEXT);
	}


	public String getCsvTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_CSV_TOOLTIP);
	}


	public String getFilterText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_FILTER_TEXT);
	}


	public String getFilterTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_FILTER_TOOLTIP);
	}


	public String getFirstPageText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_FIRST_PAGE_TEXT);
	}


	public String getFirstPageTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_FIRST_PAGE_TOOLTIP);
	}


	public String getLastPageText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_LAST_PAGE_TEXT);
	}


	public String getLastPageTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_LAST_PAGE_TOOLTIP);
	}


	public String getNextPageText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_NEXT_PAGE_TEXT);
	}


	public String getNextPageTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_NEXT_PAGE_TOOLTIP);
	}


	public String getNoResultsFound() {
		return messages.getMessage(BuilderConstants.STATUSBAR_NO_RESULTS_FOUND);
	}


	public String getPdfText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_PDF_TEXT);
	}


	public String getPdfTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_PDF_TOOLTIP);
	}


	public String getPrevPageText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_PREV_PAGE_TEXT);
	}


	public String getPrevPageTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_PREV_PAGE_TOOLTIP);
	}


	
	public String getResultsFound ( ) {
		Integer total = new Integer ( model.getLimit ( ).getTotalRows ( ) );
		//Integer from = new Integer ( model.getLimit ( ).getRowStart ( ) + 1 );
		//Integer to = new Integer ( model.getLimit ( ).getRowEnd ( ) );
		

        int currentRowsDisplayed = model.getLimit().getCurrentRowsDisplayed();
        int currentPage = model.getLimit().getPage();
        int ys = 0;
		int totalPages = 0;
		int totalRows = model.getLimit().getTotalRows();
		if (currentRowsDisplayed > 0) {
			ys = totalRows % currentRowsDisplayed;
			totalPages = ys == 0 ? totalRows / currentRowsDisplayed : totalRows / currentRowsDisplayed + 1;
		} else {
			totalPages = 1;
			currentPage = 1;
		}
		//from , to ,
		Object [ ] messageArguments = { total ,  new Integer( currentPage ) , new Integer( totalPages ) };
		return messages.getMessage ( BuilderConstants.STATUSBAR_RESULTS_FOUND , messageArguments );
	}

	public String getXlsText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_XLS_TEXT);
	}


	public String getXlsTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_XLS_TOOLTIP);
	}


	public String getXmlText() {
		return messages.getMessage(BuilderConstants.TOOLBAR_XML_TEXT);
	}


	public String getXmlTip() {
		return messages.getMessage(BuilderConstants.TOOLBAR_XML_TOOLTIP);
	}
	
	public String getLoadingText(){
		//I want put it in message
		return "Please Wait, Loading Table ....";
	}
	
	
}
